<script>
	function getwxCode() {
		return new Promise((resolve, reject)=>{
			wx.login({
				success(res) {
					let code = res.code
					resolve(code)
				},
			})
		})
	}
	import {getOpenidApi} from '@/common/api/commonApi/commonApi.js'
	export default {
		onLaunch: function() {
			// 默认中文
			let language = uni.getStorageSync('language')
			if(!language) {
				uni.setStorageSync('language','zh')
			}else{
				uni.setStorageSync('language','zh')
			}
			
			// this.$i18n.locale = 'zh'
			//#ifdef MP-WEIXIN
			//UNIAPP版本更新管理器对象
			const updateManager = uni.getUpdateManager(); // 获取更新管理器对象
			updateManager.onCheckForUpdate(function(res) {
				console.log(res,'版本更新？')
				if (res.hasUpdate) {
					updateManager.onUpdateReady(function() {
						uni.showModal({
							title: '更新提示',
							content: '新版本已经准备好，点击确定重新启动',
							showCancel: false,
							success: res => {
								if (res.confirm) {
									updateManager.applyUpdate();
								}
							}
						})
					})
					updateManager.onUpdateFailed(function() {
						uni.showModal({
							title: '提示',
							content: '检查到有新版本，但是下载失败，请检查网络设置',
							showCancel: false
						})
					})
				}
			})
			// #endif
			
			
			
			if(!uni.getStorageSync('openId')){
				getwxCode().then( res=>{
					let code = ''
					code = res
					getOpenidApi({
						js_code : code
					}).then( res=>{
						uni.setStorageSync('openId',res.result.openid )
						uni.setStorageSync('unionid',res.result.unionid )
					})
				})
				
			}
		},
		onShow: function() {
			let tabbar = this.language.tabbar
			setTimeout(()=>{
				uni.setTabBarItem({
					index: 0,
					text: tabbar.item1,
				})
				uni.setTabBarItem({
					index: 1,
					text: tabbar.item2,
				})
				uni.setTabBarItem({
					index: 2,
					text: tabbar.item3,
				})
			},1500)
		
		},
		onHide: function() {
			
		},
		
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	
</style>
